#!/usr/bin/python
# -*- coding:UTF8 -*-
from lxml import etree
import requests
import re

url = 'https://www.jkl.com.cn/shop.aspx'
user_agent = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36'}
r = requests.get(url=url, headers=user_agent).text
analytical_data = etree.HTML(r)
city_name = analytical_data.xpath('//div[@class="infoLis"]//a/text()')
city_url = analytical_data.xpath('//div[@class="infoLis"]//@href')
# print(city_name)
# print(city_url)
for city in city_url:
    spilice_url = 'https://www.jkl.com.cn/' + city
    # print(spilice_url)
    r = requests.get(url=spilice_url, headers=user_agent).text
    analytical_data = etree.HTML(r)
    tail_page = analytical_data.xpath('//a[text()="尾页"]/@href')
    # print(tail_page)
    if tail_page != []:
        regular = re.search('(\d+)', tail_page[0])
        page_num = regular.group(1)
        # print(page_num)
    else:
        page_num = 1
    print(page_num)
